package 反转链表;

public class Test2 {
    public static void main(String[] args) {

        Soulution2 soulution2 = new Soulution2();

        ListNode l5 = new ListNode(1, null);
        ListNode l4 = new ListNode(2, l5);
        ListNode l3 = new ListNode(3, l4);
        ListNode l2 = new ListNode(4, l3);
        ListNode l1 = new ListNode(5, l2);
        ListNode head = new ListNode(6, l1);

        ListNode head2 = new ListNode(1, null);

        printM(head);

        ListNode result = soulution2.reverseList(head);

        printM(result);
    }

    public static void printM(ListNode head){
        ListNode p = new ListNode();
        p = head;
        while (p != null){
            System.out.print(p.val + " ");
            p = p.next;
        }
        System.out.println();
    }
}
